package com.epfresh.supplier.dialog;


import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.epfresh.api.entity.RequestEntitySupply;
import com.epfresh.api.entity.RequestTag;
import com.epfresh.api.entity.ResponseEntity;
import com.epfresh.api.global.BaseActivity;
import com.epfresh.api.global.BaseApplication;
import com.epfresh.api.http.HttpRequest;
import com.epfresh.api.http.OnRequestListener;
import com.epfresh.supplier.R;
import com.epfresh.supplier.entity.AgentMyRecord;
import com.epfresh.supplier.entity.BuyerInfo;
import com.epfresh.supplier.entity.OfferListEntity;
import com.google.gson.Gson;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by zzq on 2017/8/23.
 */

public class OfferBuyerDialog extends Dialog {
    BaseActivity activity;
    private Button mNegativeBtn;//确定按钮
    private Button mPositiveBtn;//取消按钮
    private TextView mTitleTv;//消息标题文本
    private EditText etName,etPhone;
    private View ivPhone,ivName,ivClose;
    private boolean isTv;
    private String mTitleStr,mName,mPhone;//从外界设置的title文本
    private String mMessageStr;//从外界设置的消息文本
    //确定文本和取消文本的显示内容
    private String mNegativeStr, mPositiveStr;
    private int color;

    private onNegativeClickListener mOnNegativeClickListener;//取消按钮被点击了的监听器
    private onPositiveClickListener mOnPositiveClickListener;//确定按钮被点击了的监听器


    TextView tv_title,tv_offer_dialog_tag_1,tv_offer_dialog_tag_2,tv_number_1,tv_number_2,tv_number_3,tv_dialog_offer_time;
    String id;
    OfferListEntity.ContentBean bean;
    /**
     * 设置取消按钮的显示内容和监听
     */
    public void setOnNegativeClickListener(String str, onNegativeClickListener mOnNegativeClickListener) {
        if (!TextUtils.isEmpty(str)) {
            mNegativeStr = str;
        }
        this.mOnNegativeClickListener = mOnNegativeClickListener;
    }

    /**
     * 设置确定按钮的显示内容和监听
     */
    public void setOnPositiveClickListener(String str, onPositiveClickListener mOnPositiveClickListener) {
        if (!TextUtils.isEmpty(str)) {
            mPositiveStr = str;
        }
        this.mOnPositiveClickListener = mOnPositiveClickListener;
    }

    public OfferBuyerDialog(Context context, boolean isTv) {
        super(context, R.style.PosDialog);
        activity = (BaseActivity)context;
        this.isTv = isTv;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_offer_buyer_info);
        //按空白处不能取消动画
        setCanceledOnTouchOutside(false);

        //初始化界面控件
        initView();
        //初始化界面数据
        //初始化界面控件的事件
        initEvent();
        initData(bean);
    }

    /**
     * 初始化界面的确定和取消监听器
     */
    private void initEvent() {
        //设置确定按钮被点击后，向外界提供监听
/*        mPositiveBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mOnPositiveClickListener != null) {
                    //mOnPositiveClickListener.onPositiveClickListener(etName.getText().toString(),etPhone.getText().toString());
                }
            }
        });*/
        //设置取消按钮被点击后，向外界提供监听
/*        mNegativeBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mOnNegativeClickListener != null) {
                    mOnNegativeClickListener.onNegativeClickListener();
                }
            }
        });*/
    }
    /**
     * 初始化界面控件
     */
    private void initView() {
        tv_title = findViewById(R.id.tv_title);
        tv_offer_dialog_tag_1 = findViewById(R.id.tv_offer_dialog_tag_1);
        tv_offer_dialog_tag_2 = findViewById(R.id.tv_offer_dialog_tag_2);
        tv_number_1 = findViewById(R.id.tv_number_1);
        tv_number_2 = findViewById(R.id.tv_number_2);
        tv_number_3 = findViewById(R.id.tv_number_3);
        tv_dialog_offer_time = findViewById(R.id.tv_dialog_offer_time);
        ivClose = findViewById(R.id.iv_close);
        ivClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                OfferBuyerDialog.this.dismiss();

                //mOnNegativeClickListener.onNegativeClickListener();
            }
        });



    }

    /**
     * 设置确定按钮和取消被点击的接口
     */
    public interface onNegativeClickListener {
        void onNegativeClickListener();
    }

    public interface onPositiveClickListener {
        void onPositiveClickListener(String name, String phone);
    }
    public void show(OfferListEntity.ContentBean bean) {
        this.bean = bean;
        show();
        initData(bean);
    }

    /**
     * 初始化界面控件的显示数据
     */
    private void initData(OfferListEntity.ContentBean bean) {
        if(bean == null)
            return;
        tv_title.setText(bean.getAccountName());
        tv_offer_dialog_tag_1.setText(bean.getAccountTag());
        tv_offer_dialog_tag_2.setText(bean.getAccountSubjectName());
        tv_number_1.setText(bean.getAllOrderCnt());
        tv_number_2.setText(bean.getStoreOrderCnt());
        tv_number_3.setText(bean.getOfferReplySuccessCnt());
        tv_dialog_offer_time.setText(bean.getLastPlaceOrderTime());
    }
}
